<?php
namespace Home\Controller;
use Think\Controller;
use Home\Form\UserMessageForm;
use Common\Model\UserMessageModel;
use Common\Model\NewsModel;
use Common\Model\NoticeModel;
use Common\Model\UserModel;
class ServiceController extends HomeController {

    public function __construct()
    {
        parent::__construct();
        $this->assign('nav','Service');
    }
    public function messageBack(){
        $where['user_id']=$_SESSION['USER_KEY_ID'];
        $list=UserMessageModel::newSelf()->pagingList($where);
        $this->assign('list',$list);
        $this->display();
    }
    public function sendMessage(){
        $this->display();
    }
    public function sendMessageSub()
    {
        $data['sendee']=I('sendee');
        $data['title']=I('title');
        $data['type']=I('type');
        $data['content']=I('content');
        if ($data['sendee']=='2') {
            $this->notEmptyValidate($data['sendee'],'请填写收件人');
        }
        $this->notEmptyValidate($data['title'],'请填写留言标题');
        $this->notEmptyValidate($data['type'],'请选择留言类型');
        $this->notEmptyValidate($data['content'],'请填写留言内容');
        
        $this->inArrayValidate($data['sendee'], ['1','2'], '请 正确选择留言对象');
        $this->inArrayValidate($data['type'], ['1','2','3','4','5','6'], '请 正确选择留言类型');

        $data['add_time']=time();
        $data['sendee_id']=0;
        $sendee_name=I('sendee_name');
        $data['user_id']=$this->home_user_info['id'];
        

        if ($data['sendee']=='2') {
            $info=UserModel::newSelf()->findUserByUserName($sendee_name);
            $this->notEmptyValidate($info,'收件人不存在');
            $data['sendee_id']=$info['id'];
        }
        $data['status']=0;
        
        $res=UserMessageModel::newSelf()->add($data);
        
        $this->resReturn($res,'留言成功','留言失败');
    }
    
    public function messageInbox()
    {
        $where['sendee_id']=$_SESSION['USER_KEY_ID'];
        $list=UserMessageModel::newSelf()->pagingList($where);
        $this->assign('list',$list);
        $this->display();
    }
    public function messageOutbox()
    {
        $where['user_id']=$_SESSION['USER_KEY_ID'];
        $list=UserMessageModel::newSelf()->pagingList($where);
        $this->assign('list',$list);
        $this->display();
    }
    public function messageBossBox()
    {
        $where['user_id']=0;
        $where['sendee_id']=0;
        $list=UserMessageModel::newSelf()->pagingList($where);
        $this->assign('list',$list);
        $this->display();
    }
}